package com.efast.dmom.mgmt.controller.excel;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.bean.excel.ExcelFieldAcceptBean;
import com.efast.dmom.mgmt.bean.excel.ExcelRuleDataBean;
import com.efast.dmom.mgmt.bean.excel.TwExcelRuleBean;
import com.efast.dmom.mgmt.service.excel.ExcelUploadRuleConfigurationService;

/**
 * excel上传规则配置
 * 
 * @author wj
 * @date 2019/10/10 上午10：17
 */

@Controller
@RequestMapping(value = "/Configuration")
public class ExcelUploadRuleConfigurationController {
	
	@Autowired
	private ExcelUploadRuleConfigurationService excelUploadRuleConfigurationService;
	
	//模糊查询表名
	@RequestMapping(value = "/getTableName/{name}", method = RequestMethod.POST)
	public @ResponseBody List<String> getTableName(@PathVariable String name){
		
		return excelUploadRuleConfigurationService.getTableName(name);
	} 
	
	//通过表名查询出来所有的字段名
	@RequestMapping(value="/getFieldName/{tableName}", method = RequestMethod.POST)
	public @ResponseBody List<ExcelFieldAcceptBean> getFiledNameAndcommentByTableName(@PathVariable String tableName){
		return excelUploadRuleConfigurationService.getFiledNameAndcommentByTableName(tableName);
	}
	
	//规则表查询
	@RequestMapping(value="/getInformation/{tableName}", method = RequestMethod.POST)
	public @ResponseBody List<ExcelRuleDataBean> getInformationByRuleTable(@PathVariable String tableName){
		return excelUploadRuleConfigurationService.getInformationByRuleTable(tableName);
	}
	
	//生成对应表的规则
	@RequestMapping(value="/createExcelRule", method = RequestMethod.POST)
	public @ResponseBody ResultBean createTableExcelRule(@RequestBody TwExcelRuleBean data){
		return excelUploadRuleConfigurationService.createTableExcelRule(data);
	}
	
	//更新规则表的信息
	@RequestMapping(value="/updateExcelRule", method = RequestMethod.POST)
	public @ResponseBody ResultBean updateTableExcelRule(@RequestBody TwExcelRuleBean data){
		ResultBean resultBean =excelUploadRuleConfigurationService.updateTableExcelRule(data);
		return resultBean;
	}
	
	//删除规则表的信息
	@RequestMapping(value="/deleteExcelRule", method = RequestMethod.POST)
	public @ResponseBody ResultBean deleteTableExcelRule(@RequestBody TwExcelRuleBean data){
		ResultBean resultBean = new ResultBean(true,"'");
		excelUploadRuleConfigurationService.deleteTableExcelRule(data);
		resultBean.setSuccess(true);
		resultBean.setMessage("删除成功！");
		return resultBean;
	}
	
	//新增相应规则表的信息
	@RequestMapping(value="/saveExcelRule", method = RequestMethod.POST)
	public @ResponseBody void saveTableExcelRule(@RequestBody TwExcelRuleBean data){
		excelUploadRuleConfigurationService.saveTableExcelRule(data);
	}
	
}
